Computer programs are groups of instructions that describe actions to be performed by a computer or other processor-based device. When a computer program is loaded and executed on computer hardware, the computer will behave in a predetermined manner by following the instructions of the computer program. Accordingly, the computer becomes a specialized machine that performs the tasks prescribed by the instructions.
A programmer using one or more programming languages creates the instructions comprising a computer program. Typically, source code is specified or edited by a programmer manually and/or with help of an integrated development environment (IDE). Subsequently, the source code can be compiled or otherwise transformed by another program into computer instructions executable by a computer or like device.
By way of example, a programmer may choose to implement code utilizing an object-oriented programming language (e.g., C#®, Java® . . . ). In accordance with such a paradigm, programmers will create a number of classes identifying properties and characteristics of an abstract thing as well as methods describing class behavior or abilities. Specific programmatic logic can then be specified as interactions between instances of classes or objects, among other things. Subsequently, executable code for a particular machine can be produced by an associated compiler. Alternatively, code can be transformed into intermediate code for a target virtual machine to facilitate execution on multiple computer platforms via further compilation or interpretation of the intermediate code.
Object-oriented languages operate with respect plurality of unique programming features not included by other languages such as those described as prototype and/or object based. Three related concepts supported by true object oriented programming models are classes, inheritance and polymorphism.
A class is a data structure that merges state and actions into a single unit. In a class, state is captured by variables or fields, while actions are encapsulated by methods and/or functions. Among other things, a class provides a formal definition for instances of classes or objects. In other words, classes identify an associated object signature or pattern. Classes support both inheritance and polymorphism.
Inheritance pertains to composition of new classes utilizing previously defined classes. The new class sometimes called a subclass or derived class inherits attributes and behavior of a pre-existing base class. Inheritance provides a mechanism to specialize classes via overriding and/or extending inherited behavior.
Polymorphism refers to the ability to change meaning or behavior based on context associated with invocation. More particularly, a single definition/declaration can be utilized with different data types or classes of objects, wherein behavior is dictated by a type or class.
Inheritance and polymorphism intersect where derived classes override base class behavior. For example, a class Chihuahua can be derived from a base class Dog, where Dog has a single method bark( ) that returns woof. The class Chihuahua inherits this method. However, this specialized class can override the implementation of bark( ) to return a higher pitch bark associated with this particular small dog. Accordingly, bark( ) is polymorphic in that its implementation depends on an object class, namely Dog and Chihuahua. In some languages, bark( ) is referred to as a virtual method for the same reason.